This also makes the “target” Return and St.dev for the next 12 months
setwd("/Users/rout/Desktop/Dropbox/2019m6-46892-MSBA-fin/RCode/Assign6")
source("Main.A6.R")
## Loading required package: ggplot2
## Loading required package: grid
## Loading required package: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Loading required package: reshape2
## Loading required package: RColorBrewer
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: glmnet
## Loading required package: Matrix
## Loading required package: foreach
## Loaded glmnet 2.0-5
## Warning in FUN(X[[i]], ...): NaNs produced
## Warning in FUN(X[[i]], ...): NaNs produced
## Warning in FUN(X[[i]], ...): NaNs produced
## Warning in FUN(X[[i]], ...): NaNs produced
## Warning in FUN(X[[i]], ...): NaNs produced
## [1] "Fin" "Telcm" "Rtail" "Util" "Oil" "Agric" "Autos" "Whlsl"
## [9] "Beer" "Toys" "Banks"
This is in RunsForClass.R
First – Lets preduct some Expected Returns (12 month horison)
My parameter Interesting is selecting a lambda regularizer parameter. I did this by picking from the st.dev of the forecast. If you set the regularizer to really big, the st.dev of the forecast goes to zero. I am using my prior that the variation in E[R] should not be zero and not too big
ER<-"E[R| date t]"
z<- Forecast(
D=Data,
what=c("Market"),
use=c("CONSTANT","DPratio"),
Interesting=c(0.5)
)
## [1] "R:Market"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="DP Ratio")
print(p)
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=c("CONSTANT","DPratio"),
Interesting=c(0.5)
)
## [1] "R:Market"
## [1] "R:Fin"
## [1] "R:Telcm"
## [1] "R:Rtail"
## [1] "R:Util"
## [1] "R:Oil"
## [1] "R:Agric"
## [1] "R:Autos"
## [1] "R:Whlsl"
## [1] "R:Beer"
## [1] "R:Toys"
## [1] "R:Banks"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="DP Ratio")
print(p)
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=c("CONSTANT","PDratio","gaip","recession","CreditSpread","TermSpreadL","unrate"),
Interesting=c(0.05)
)
## [1] "R:Market"
## [1] "R:Fin"
## [1] "R:Telcm"
## [1] "R:Rtail"
## [1] "R:Util"
## [1] "R:Oil"
## [1] "R:Agric"
## [1] "R:Autos"
## [1] "R:Whlsl"
## [1] "R:Beer"
## [1] "R:Toys"
## [1] "R:Banks"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="DP Ratio,int rate, unemployment")
print(p)
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=c("inflation","unrate"), # Growth IP
Interesting=c(0.05)
)
## [1] "R:Market"
## [1] "R:Fin"
## [1] "R:Telcm"
## [1] "R:Rtail"
## [1] "R:Util"
## [1] "R:Oil"
## [1] "R:Agric"
## [1] "R:Autos"
## [1] "R:Whlsl"
## [1] "R:Beer"
## [1] "R:Toys"
## [1] "R:Banks"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="inflation,unemployment")
print(p)
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=c("CONSTANT","recession"), # Growth IP
Interesting=c(0.05)
)
## [1] "R:Market"
## [1] "R:Fin"
## [1] "R:Telcm"
## [1] "R:Rtail"
## [1] "R:Util"
## [1] "R:Oil"
## [1] "R:Agric"
## [1] "R:Autos"
## [1] "R:Whlsl"
## [1] "R:Beer"
## [1] "R:Toys"
## [1] "R:Banks"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="Just nber recession {1,0}")
print(p)
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=c("FEDFUNDS","TermSpreadS","TermSpreadL", "CreditSpread"), # Growth IP
Interesting=c(0.05)
)
## [1] "R:Market"
## [1] "R:Fin"
## [1] "R:Telcm"
## [1] "R:Rtail"
## [1] "R:Util"
## [1] "R:Oil"
## [1] "R:Agric"
## [1] "R:Autos"
## [1] "R:Whlsl"
## [1] "R:Beer"
## [1] "R:Toys"
## [1] "R:Banks"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="just interest rates")
print(p)
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=c("gaip","gacr"), # Growth IP
Interesting=c(0.1)
)
## [1] "R:Market"
## [1] "R:Fin"
## [1] "R:Telcm"
## [1] "R:Rtail"
## [1] "R:Util"
## [1] "R:Oil"
## [1] "R:Agric"
## [1] "R:Autos"
## [1] "R:Whlsl"
## [1] "R:Beer"
## [1] "R:Toys"
## [1] "R:Banks"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="recent growth")
print(p)
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=colnames(P[,grepl("ga",colnames(P))]), # Growth IP
Interesting=c(0.01)
)
## [1] "R:Market"
## [1] "R:Fin"
## [1] "R:Telcm"
## [1] "R:Rtail"
## [1] "R:Util"
## [1] "R:Oil"
## [1] "R:Agric"
## [1] "R:Autos"
## [1] "R:Whlsl"
## [1] "R:Beer"
## [1] "R:Toys"
## [1] "R:Banks"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="recent growth (many)")
print(p)
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=colnames(P[,-c(1:3)]), # EVERYTHING
Interesting=c(0.01)
)
## [1] "R:Market"
## [1] "R:Fin"
## [1] "R:Telcm"
## [1] "R:Rtail"
## [1] "R:Util"
## [1] "R:Oil"
## [1] "R:Agric"
## [1] "R:Autos"
## [1] "R:Whlsl"
## [1] "R:Beer"
## [1] "R:Toys"
## [1] "R:Banks"
p<-Plot.Forecast(z,clip=c(0.01,.2),target=ER,title="Everything")
print(p)
This is predicting the volatility over the next 12 months. I calcualted this as V= sum(eR^2) - (average eR)^2. then sigma=sqrt(V). there are other ways to define this.
In general volatility is more predictible
VR<-"sigma[R| date t]"
z<- Forecast(
D=Data,
what=c("Market"),
use=c("CONSTANT","DPratio"),
Interesting=c(0.1,0.25,0.5,0.75,.9),
LHS="V"
)
## [1] "V:Market"
Plot.Forecast(z,clip=c(0.01,.25),target=VR,title="DP Ratio (several lambda)",h=sqrt(12),highlight="")
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=c("CONSTANT","DPratio"),
Interesting=c(0.5),
LHS="V"
)
## [1] "V:Market"
## [1] "V:Fin"
## [1] "V:Telcm"
## [1] "V:Rtail"
## [1] "V:Util"
## [1] "V:Oil"
## [1] "V:Agric"
## [1] "V:Autos"
## [1] "V:Whlsl"
## [1] "V:Beer"
## [1] "V:Toys"
## [1] "V:Banks"
Plot.Forecast(z,clip=c(0.01,.25),target=VR,title="DP Ratio",h=sqrt(12))
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=c("CONSTANT","recession"), # Growth IP
Interesting=c(0.5),
LHS="V"
)
## [1] "V:Market"
## [1] "V:Fin"
## [1] "V:Telcm"
## [1] "V:Rtail"
## [1] "V:Util"
## [1] "V:Oil"
## [1] "V:Agric"
## [1] "V:Autos"
## [1] "V:Whlsl"
## [1] "V:Beer"
## [1] "V:Toys"
## [1] "V:Banks"
Plot.Forecast(z,clip=c(0.01,.25),target=VR,title="recession",h=sqrt(12))
z<- Forecast(
D=Data,
what=c("Market","Rtail", "Util", "Oil"),
use=c("CONSTANT","recession"), # Growth IP
Interesting=c(0.5),
LHS="V"
)
## [1] "V:Market"
## [1] "V:Rtail"
## [1] "V:Util"
## [1] "V:Oil"
Plot.Forecast(z,clip=c(0.01,.25),target=VR,title="recession",h=sqrt(12))
z<- Forecast(
D=Data,
what=c("Market",Use.Industries),
use=colnames(P[,-c(1:3)]), # EVERYTHING
Interesting=c(0.01),
LHS="V"
)
## [1] "V:Market"
## [1] "V:Fin"
## [1] "V:Telcm"
## [1] "V:Rtail"
## [1] "V:Util"
## [1] "V:Oil"
## [1] "V:Agric"
## [1] "V:Autos"
## [1] "V:Whlsl"
## [1] "V:Beer"
## [1] "V:Toys"
## [1] "V:Banks"
Plot.Forecast(z,clip=c(0.01,.25),target=VR,title="Everything",h=sqrt(12))